package com.google.code.garbagecan.cassandrastudy.astyanax;


import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;

public class DBUtils {

	private static final String HOST = "perf3";
	private static final int PORT = 9160;
	private static final String CLUSTER_NAME = "benchmark";
	private static final String KEY_SPACE = "demo4";

	public static AstyanaxContext getContext() {
		AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
				.forCluster(CLUSTER_NAME)
				.forKeyspace(KEY_SPACE)
				.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
						.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
						.setCqlVersion("3.0.0")
						.setTargetCassandraVersion("1.2.4")
						//.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_ONE)
						//.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_ANY)
				)
				.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
						.setPort(PORT)
						.setMaxConnsPerHost(50)
						.setSeeds(HOST + ":" + PORT)
						.setConnectTimeout(300 * 1000)
						.setSocketTimeout(300 * 1000)
				)
				.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
				.buildKeyspace(ThriftFamilyFactory.getInstance());

		return context;
	}
}
